home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Q:order of evaluation
- Date: Mon, 29 Jan 1996 12:56:02 GMT
- Organization: Netcom
- Message-ID: <310cbc99.219827136@nntp.ix.netcom.com>
- References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com> <4dpcfo$293@clarknet.clark.net> <hamilton-2401960104020001@dialup-86.austin.io.com> <3108c867.40236096@nntp.ix.netcom.com> <4eb6kq$ksf@gazette.tandem.com> <31098f8f.11689344@nntp.ix.netcom.com> <4ei45v$mci@axl02it.ntc.nokia.com>
- NNTP-Posting-Host: ix-dc7-18.ix.netcom.com
- X-NETCOM-Date: Mon Jan 29 4:55:24 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Risto Lankinen <risto.lankinen@ntc.nokia.com> wrote:
-
- > Hi!
- >
- > miker3@ix.netcom.com (Mike Rubenstein) wrote:
- > >yun_yeogirl <yyg> wrote:
- > >
- > >> Michael M Rubenstein wrote :
- > >>
- > >> [Example:
- > >> i = v[i++]; // the behavior is undefined
- > >>
- > >> i = ++i + 1; // the behavior is undefined
- > >>
- > [etc...]
- >
- > Isn't the mere existence of this discussion an adequate reason for
- > reconsidering the standard when it comes to the evaluation order of
- > such expressions? What I mean is, why does the standard *need* to
- > specify that something is 'undefined' when they could be 'defined'
- > anyway. This would have the added bonus that no existing programs
- > conforming to the standard won't break simply because they were not
- > allowed to make assumptions about undefined behaviour, whereas the
- > new programs would have the added power of expression without fear
- > of the compilers misinterpreting the intent.
- >
- > For example, instead of...
- >
- > >> i = ++i + 1; // the behavior is undefined
- >
- > .. one could define in the standard...
- >
- > >> i = ++i + 1; // operator+() evaluates and executes
- > >> // its arguments in the order of their
- > >> // associativity, ie. '++i' first, the
- > >> // constant expression '1' next, and
- > >> // the operator+() last. Finally, the
- > >> // result is assigned to 'i'. Thus the
- > >> // example equals to 'i = i + 2'.
- >
- > .. and within one version cycle all compilers will behave same.
- >
- > Or, for curiosity's sake, why not?
-
- I don't see the fact that some people just don't bother to learn the
- language as a reason, in itself, for changing the standard. Still,
- there would be some advantages to specifying order more closely.
-
- But, there would also be disadvantages. Specification of order cuts
- down on optimization possibilities. On register-poor machines, it is
- usually advantageous to evaluate the more complicated subexpression
- first, but your rule would prohibit this optimization. The expression
-
- a + (b + (c + (d * e * f * g)))
-
- can be evaluated with only one intermediate if the compiler is allowed
- to select the order, but would require 4 under your rule. Requiring
- incrementation to take place immediately places still more burden on
- the registers.
-
- Is there any evidence that those who do not bother to learn the
- present rules will bother to learn the new rules for ordering of
- expressions? I think not. Look at the problems we have with very
- simple things. The subclause on fflush() (ISO 7.9.5.2) is 12 lines of
- text. The first paragraph of the description is
-
- If stream points to an output stream or an update stream in
- which the most recent operation was not input, the fflush
- function causes any unwritten data for that stream to be
- delivered to the host environment to be written to the file;
- otherwise the behavior is undefined.
-
- Yet we still have people suggesting fflush(stdin).
-
-
- Michael M Rubenstein
-